
package com.service.impl;


import com.dao.TokenDao;
import com.domain.entity.TokenEntity;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.baomidou.mybatisplus.service.impl.ServiceImpl;
import com.dao.UserDao;
import com.domain.entity.UserEntity;
import com.service.UserService;
import org.springframework.transaction.annotation.Transactional;


@Service("userService")
public class UserServiceImpl extends ServiceImpl<UserDao, UserEntity> implements UserService {

	@Autowired
	private UserDao userDao;

	@Autowired
	private TokenDao tokenDao;


	@Override
	@Transactional
	public void updateTokenAndUser(UserEntity userEntity) {

		//更新user表和token表
		userDao.updateById(userEntity);

		TokenEntity tokenEntity = new TokenEntity();
		Long id = userEntity.getId();
		tokenEntity.setUsername(userEntity.getUsername());
		tokenEntity.setUserid(id);

		tokenDao.update(tokenEntity, new EntityWrapper<TokenEntity>().eq("userid",id));

	}
}
